package edu.towson.cis.cosc490.wegher.lab4;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class AddNewItemActivity extends Activity {

	EditText editTextMessage;
	RadioButton highRadio;
	RadioButton mediumRadio;
	RadioButton lowRadio;
	CheckBox finishedBox;
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_item);
        editTextMessage=(EditText)findViewById(R.id.editText1);
        highRadio = (RadioButton)findViewById(R.id.radio0);
        mediumRadio = (RadioButton)findViewById(R.id.radio1);
        lowRadio = (RadioButton)findViewById(R.id.radio2);
        finishedBox = (CheckBox)findViewById(R.id.checkBox1);
    }
    
	public void addItem(View V)
	{
		// get the Entered  message
		String item = editTextMessage.getText().toString();
		Intent intentMessage = new Intent();
		
		// Debugging toast
		Toast.makeText(AddNewItemActivity.this,
					   "Add new item: " + item,
					   Toast.LENGTH_LONG).show();
		
		if(finishedBox.isChecked())
			intentMessage.putExtra("FINISHED", "TRUE");
		else
			intentMessage.putExtra("FINISHED", "FALSE");
		
		if(highRadio.isChecked()) {
			intentMessage.putExtra("PRIORITY", "HIGH");
		} else if(mediumRadio.isChecked()) {
			intentMessage.putExtra("PRIORITY", "MEDIUM");
		} else if(lowRadio.isChecked()) {
			intentMessage.putExtra("PRIORITY", "LOW");
		}
		
		// put the message in Intent
		intentMessage.putExtra("ITEM", item);

		setResult(2,intentMessage);
	
        finish();
	}
    
}
